<?php

namespace app\crm\controller;

use app\crm\model\ReceiveTask as  ReceiveModel;
use app\crm\model\Task as TaskModel;
use think\Db;


class Task extends BaseController
{
    //任务列表
    public function getList($status = 0, $start = '', $end = '', $user_id = '', $number = '')
    {
        $where = [];
        $url_param = [];
        if ($status == 1) {
            $where['status'] = $status;
            $url_param['query']['status'] = $status;
        }
        if (!empty($start)) {
            $where['add_time'][] = ['>=', $start];
            $url_param['query']['start'] = $start;
        }
        if (!empty($end)) {
            $where['add_time'][] = ['<=', $end];
            $url_param['query']['end'] = $end;
        }
        if (!empty($user_id)) {
            $where['user_id'] = $user_id;
            $url_param['query']['user_id'] = $user_id;
        }
        if (!empty($number)) {
            $where['number'] = $number;
            $url_param['query']['number'] = $number;
        }
        $list = TaskModel::where($where)->with('user')->order('update_time desc')->paginate(10, false, $url_param);
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);
        return $this->fetch();
    }

    //接收任务列表
    public function receiveList($task_id)
    {
        $cond = ['task_id' => $task_id];
        $list = ReceiveModel::where($cond)->with('user,task')->order('add_time desc')->paginate(10);
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);
        return $this->fetch();
    }
}